package plants.ants.com;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class PlantsVsAntsActivity extends Activity {
	private Bitmap map;
	private float scaleWidth, scaleHeight;
	private float zoom = 0.0f;
	private ImageView mainMap;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		// makes it so that turning the screen does not turn the display
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		mainMap = (ImageView) findViewById(R.id.mapImage);

		SetBitMap();
	}

	// Sets the large scale map (zoomed out)
	public void SetBitMap() {
		map = BitmapFactory
				.decodeFile("/PlantsVsAnts/res/drawable-ldpi/mapicon.png");

		float imageWidth = (float) map.getWidth();
		float imageHeight = (float) map.getHeight();
		float newHeight = imageHeight / (imageWidth / 550);
		scaleWidth = 550 / imageWidth;
		scaleHeight = newHeight / 320;
		mainMap.setImageBitmap(map);
		SetImageMatrix();
	}

	void SetImageMatrix() {
		Matrix mtrx = new Matrix();
		mtrx.postScale(scaleWidth, scaleHeight);
		mainMap.setImageMatrix(mtrx);
		mainMap.setScaleType(ScaleType.MATRIX);
		mainMap.invalidate();

	}

	void ZoomIn(float zoom) {
		zoom += 0.01;
		scaleWidth += zoom;
		scaleHeight += zoom;
		SetBitMap();

	}

	void ZoomOut(float zoom) {
		zoom -= 0.01;
		scaleWidth -= zoom;
		scaleHeight -= zoom;
		SetBitMap();
	}
}